﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MoetutuTranslate.Helper
{
        class PrintLog
        {
            private static string printLogPath = ".\\TempPath\\Runlog.txt";
            /// <summary>
            /// string format  支持三个参数拼接。
            /// </summary>
            /// <param name="format"></param>
            /// <param name="arg0"></param>
            /// <param name="arg1"></param>
            /// <param name="arg2"></param>
            public static void Log(string format, object arg0, object arg1, object arg2)
            {
                String text = string.Format(format, arg0, arg1, arg2);
                Console.WriteLine(text);
                WriteLog(text);
            }
            /// <summary>
            /// string format  支持两个个参数拼接。
            /// </summary>
            /// <param name="format"></param>
            /// <param name="arg0"></param>
            /// <param name="arg1"></param>

            public static void Log(string format, object arg0, object arg1)
            {
                String text = string.Format(format, arg0, arg1);
                Console.WriteLine(text);
                WriteLog(text);
            }
            /// <summary>
            ///  string format  支持一个参数拼接。
            /// </summary>
            /// <param name="format"></param>
            /// <param name="arg0"></param>
            public static void Log(string format, object arg0)
            {
                String text = string.Format(format, arg0);
                Console.WriteLine(text);
                WriteLog(text);
            }
            public static void Log(String Log)
            {
                Console.WriteLine(Log);
                WriteLog(Log);
            }

            private static void WriteLog(string Log)
            {

                if (!Directory.Exists(Path.GetDirectoryName(printLogPath)))
                    Directory.CreateDirectory(Path.GetDirectoryName(printLogPath));//由于printLog要复制多个项目，故专门实现一次
               
                    File.AppendAllText(printLogPath, "\r\n" + Log, Encoding.UTF8);
            }

            public static void Log(System.Exception Log)
            {
                String text = Log.ToString();
                Console.WriteLine(text);
                WriteLog(text);
            }


            public static void Log(List<String> Log)
            {

                foreach (String line in Log)
                {
                    Console.WriteLine(line);
                    WriteLog(line);
                }
            }
        }
    }

